/******************************************************************************
 * FILE NAME:
 *  trs_types_def.h
 *
 * DESCRIPTION:
 * This file contains the function handle for configuration transport_layer
 * of syslog project.
 *
 * DESIGN REFERENCE:
 *
 *
 * REVISION HISTORY   :
 * Date            Author               REASON
 * 06.08.2013      Thuan Nguyen         Creation
 * 08.08.2013		Trinh Lam			Add configuration for transport layer
 *
 * Copyright 2005, NET
 * ***************************************************************************/

#ifndef TP_CONFIGURE_HANDLE_H_
#define TP_CONFIGURE_HANDLE_H_

#include"../h/trs_types_def.h"



U8 *sock_str[] = {"SOCK_STREAM",
					"SOCK_DGRAM",
					"SOCK_RAW",
					"SOCK_RDM",
					"SOCK_SEQPACKET",
					"SOCK_DCCP",
					"SOCK_PACKET",
					"SOCK_CLOEXEC",
					"SOCK_NONBLOCK"
					};

U32 sock_val[] = { 1, 2, 3, 4, 5, 6, 10, 524288, 2048 };

U8 *af_str[] = {"AF_UNSPEC",
					"AF_LOCAL",
					"AF_UNIX",
					"AF_FILE",
					"AF_INET",
					"AF_AX25",
					"AF_IPX",
					"AF_APPLETALK",
					"AF_NETROM",
					"AF_BRIDGE",
					"AF_ATMPVC",
					"AF_X25",
					"AF_INET6",
					"AF_ROSE",
					"AF_DECnet",
					"AF_NETBEUI",
					"AF_SECURITY",
					"AF_KEY",
					"AF_NETLINK",
					"AF_ROUTE",
					"AF_PACKET",
					"AF_ASH",
					"AF_ECONET",
					"AF_ATMSVC",
					"AF_RDS",
					"AF_SNA",
					"AF_IRDA",
					"AF_PPPOX",
					"AF_WANPIPE",
					"AF_LLC",
					"AF_CAN",
					"AF_TIPC",
					"AF_BLUETOOTH",
					"AF_IUCV",
					"AF_RXRPC",
					"AF_ISDN",
					"AF_PHONET",
					"AF_IEEE802154",
					"AF_MAX"
					};

U32 af_val[] = { 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 29, 30, 31,
				32, 33, 34, 35, 36, 37};

U32 trs_read_config_func(U8 *fileName);

U32 trs_read_config_func(U8 *fileName)
{
    char test;
    char xml_element = '\0';
    config_struct_t list_config;

    xmlTextReaderPtr reader;

    reader = xmlReaderForFile(fileName, NULL, 0);

    char *temp;

    int i;

    while(xmlTextReaderRead(reader)) {
        switch(xmlTextReaderNodeType(reader)) {
            case XML_READER_TYPE_ELEMENT:


                for(i = 0 ; i < xmlTextReaderDepth(reader) ; i++)
                    printf("\t");

                temp = (char *)xmlTextReaderConstName(reader);

                if(!strcmp(temp, XML_PORT_STR))
                    xml_element = XML_PORT;
                else if(!strcmp(temp, XML_PROTOCOL_STR))
                    xml_element = XML_PROTOCOL;
                else if(!strcmp(temp, XML_PROTOCOL_TYPE_STR))
                    xml_element = XML_PROTOCOL_TYPE;
                else if(!strcmp(temp, XML_TYPE_STR))
                    xml_element = XML_TYPE;
                else
                    xml_element = 0;

                printf("Element: %s", temp);

                xmlTextReaderMoveToElement(reader);

                continue;

            case XML_READER_TYPE_TEXT:
                temp = (char *)xmlTextReaderConstValue(reader);

                for(i = 0 ; i < xmlTextReaderDepth(reader) ; i++)
                {
                }

                if(xml_element)
                {
                    switch(xml_element)
                    {
                        case XML_PORT:
                            list_config.port = atoi(temp);
                            break;

                        case XML_PROTOCOL:
                            if(!strcmp(temp, XML_PROTOCOL_TCP_STR))
                                list_config.protocol = XML_PROTOCOL_TCP;
                            else if(!strcmp(temp, XML_PROTOCOL_UDP_STR))
                                list_config.protocol = XML_PROTOCOL_UDP;
                            else
                                list_config.protocol = 255;
                            break;

                        case XML_PROTOCOL_TYPE:
							for(i = 0; i<XML_MAX_SOCK; i++)
							{
								if(!strcmp(temp, sock_str[i]))
									break;
							}
                            list_config.protocol_type = sock_val[i];
                            break;

                        case XML_TYPE:
							for(i = 0; i<XML_MAX_AF; i++)
							{
								if(!strcmp(temp, af_str[i]))
									break;
							}
                            list_config.type = af_val[i];
                            break;

                        default:
                            break;
                    }
                }
                continue;
        }
    }

    xmlFreeTextReader(reader);
    xmlCleanupParser();

    return 0;
}

#endif
